package com.maimang.platform.common.utils.excel;

import java.util.*;

/**
 * @author Rocky
 * @version 1.0.0
 * @classname TestMain
 * @description <br>Excel测试类</br>
 * @date 2019-10-22 13:58
 * @email jintaozhao@qq.com
 */
public class TestMain {

	public static void main(String[] args) throws Exception {
		// 单级的表头
		Map<String, String> map = new HashMap<String, String>();
		map.put("登录名", "u_login_id");
		Map<String, String> map1 = new HashMap<String, String>();
		map1.put("用户名", "u_name");
		Map<String, String> map2 = new HashMap<String, String>();
		map2.put("角色", "u_role");
		Map<String, String> map3 = new HashMap<String, String>();
		map3.put("部门", "u_dep");//d_name
		Map<String, String> map4 = new HashMap<String, String>();
		map4.put("用户类型", "u_type");
		List<Map<String, String>> titleList = new ArrayList<>();
		titleList.add(map);
		titleList.add(map1);
		titleList.add(map2);
		titleList.add(map3);
		titleList.add(map4);
		//单级的 行内数据
		List<Map<String, String>> rowList = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			Map m = new HashMap<String, String>();
			m.put("u_login_id", "登录名" + i);
			m.put("u_name", "张三" + i);
			m.put("u_role", "角色" + i);
			m.put("u_dep", "部门" + i);
			m.put("u_type", "用户类型" + i);
			rowList.add(m);
		}
		ExcelTool excelTool = new ExcelTool("单级表头的表格", 15, 20);
		List<Column> titleData = excelTool.columnTransformer(titleList);
		// excelTool.exportExcel(titleData,rowList,"D://outExcel0.xls",true,false);

		// List<Map>数据 多级表头,数据如下:
		//        登录名  姓名       aa
		//                      角色    部门
		List<Map<String, String>> titleList0 = new ArrayList<>();
		Map<String, String> titleMap = new HashMap<String, String>();
		titleMap.put("id", "11");
		titleMap.put("pid", "0");
		titleMap.put("content", "登录名");
		titleMap.put("fielName", "u_login_id");
		Map<String, String> titleMap1 = new HashMap<String, String>();
		titleMap1.put("id", "1");
		titleMap1.put("pid", "0");
		titleMap1.put("content", "姓名");
		titleMap1.put("fielName", "u_name");
		Map<String, String> titleMap2 = new HashMap<String, String>();
		titleMap2.put("id", "2");
		titleMap2.put("pid", "0");
		titleMap2.put("content", "角色加部门");
		titleMap2.put("fielName", null);
		Map<String, String> titleMap3 = new HashMap<String, String>();
		titleMap3.put("id", "3");
		titleMap3.put("pid", "2");
		titleMap3.put("content", "角色");
		titleMap3.put("fielName", "u_role");
		Map<String, String> titleMap4 = new HashMap<String, String>();
		titleMap4.put("id", "4");
		titleMap4.put("pid", "2");
		titleMap4.put("content", "部门");
		titleMap4.put("fielName", "u_dep");
		Map<String, String> titleMap5 = new HashMap<String, String>();
		titleMap5.put("id", "22");
		titleMap5.put("pid", "0");
		titleMap5.put("content", "角色加部门1");
		titleMap5.put("fielName", null);
		Map<String, String> titleMap6 = new HashMap<String, String>();
		titleMap6.put("id", "22_1");
		titleMap6.put("pid", "22");
		titleMap6.put("content", "角色1");
		titleMap6.put("fielName", "u_role");
		Map<String, String> titleMap7 = new HashMap<String, String>();
		titleMap7.put("id", "22_2");
		titleMap7.put("pid", "22");
		titleMap7.put("content", "部门1");
		titleMap7.put("fielName", "u_dep");
		titleList0.add(titleMap);
		titleList0.add(titleMap1);
		titleList0.add(titleMap2);
		titleList0.add(titleMap3);
		titleList0.add(titleMap4);
		titleList0.add(titleMap5);
		titleList0.add(titleMap6);
		titleList0.add(titleMap7);
		// 单级的 行内数据
		List<Map<String, String>> rowList0 = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			Map m = new HashMap<String, String>();
			m.put("u_login_id", "登录名" + i);
			m.put("u_name", "张三" + i);
			m.put("u_role", "角色" + i);
			m.put("u_dep", "部门" + i);
			m.put("u_type", "用户类型" + i);
			rowList0.add(m);
		}
		ExcelTool excelTool0 = new ExcelTool("List<Map>数据 多级表头表格", 20, 20);
		List<Column> titleData0 = excelTool.columnTransformer(titleList, "id", "pid", "content", "fielName", "0");
		// excelTool.exportExcel(titleData0, rowList0, "D://outExcel1.xlsx", true, false);

		//实体类（entity）数据 多级表头,数据如下:
		//        登录名  姓名       aa
		//                      角色    部门
		List<TitleEntity> titleList2 = new ArrayList<>();
		TitleEntity titleEntity0 = new TitleEntity("0", null, "总表", null);
		TitleEntity titleEntity = new TitleEntity("11", "0", "登录名2", "u_login_id");
		TitleEntity titleEntity1 = new TitleEntity("1", "0", "姓名", "u_name");
		TitleEntity titleEntity11 = new TitleEntity("1_1", "1", "姓名1", "u_name");
		TitleEntity titleEntity2 = new TitleEntity("2", "0", "角色加部门", null);
		TitleEntity titleEntity3 = new TitleEntity("3", "2", "角色", "u_role");
		TitleEntity titleEntity4 = new TitleEntity("4", "2", "部门", "u_dep");
		TitleEntity titleEntity5 = new TitleEntity("33", null, "角色加部门1", null);
		TitleEntity titleEntity6 = new TitleEntity("dept33", "33", "角色33", "u_role");
		TitleEntity titleEntity7 = new TitleEntity("33_2", "dept33", "部门33", "u_dep");
		TitleEntity titleEntity8 = new TitleEntity("44", "0", "角色加部门2", null);
		TitleEntity titleEntity9 = new TitleEntity("44_1", "44", "角色44", "u_role");
		TitleEntity titleEntity10 = new TitleEntity("44_2", "44", "部门44", "u_dep");
		TitleEntity titleEntity12 = new TitleEntity("44_3", "44_2", "44_2", "u_dep");
		titleList2.add(titleEntity0);
		titleList2.add(titleEntity);
		titleList2.add(titleEntity1);
		titleList2.add(titleEntity2);
		titleList2.add(titleEntity3);
		titleList2.add(titleEntity4);
		titleList2.add(titleEntity5);
		titleList2.add(titleEntity6);
		titleList2.add(titleEntity7);
		titleList2.add(titleEntity8);
		titleList2.add(titleEntity9);
		titleList2.add(titleEntity10);
		titleList2.add(titleEntity11);
		titleList2.add(titleEntity12);
		//单级的 行内数据
		List<Map<String, String>> rowList2 = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			Map m = new HashMap<String, String>();
			m.put("u_login_id", "登录名" + i);
			m.put("u_name", "张三" + i);
			m.put("u_role", "角色" + i);
			m.put("u_dep", "部门" + i);
			m.put("u_type", "用户类型" + i);
			rowList2.add(m);
		}

		Map<String, String> sheetNames = new LinkedHashMap<>();
		sheetNames.put("a", "表格hello");
		sheetNames.put("b", "表格world，我的表格");
		sheetNames.put("c", "HelloWorld");

		ExcelTool excelTool2 = new ExcelTool(sheetNames, 20, 20);
		List<Column> titleData2 = excelTool.columnTransformer(titleList2, "id", "pid", "content", "fieldName", "0");

		Map columnsMap = new LinkedHashMap();
		columnsMap.put("a", titleData2);
		columnsMap.put("b", titleData2);
		columnsMap.put("c", titleData2);
		// XSSFWorkbook wb1 = excelTool.exportWorkbook(titleData, rowList, true);
		// ExcelTool excelTool2 = new ExcelTool("表格", 20, 20);

		//单级的 行内数据
		List<Map<String, String>> rowList3 = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			Map m = new HashMap<String, String>();
			m.put("u_login_id", "用户名" + i);
			m.put("u_name", "王麻子" + i);
			m.put("u_role", "用户角色" + i);
			m.put("u_dep", "部门名称" + i);
			m.put("u_type", "用户类型" + i);
			rowList3.add(m);
		}
		// XSSFWorkbook wb2 = excelTool2.exportWorkbook(titleData, rowList2, true);
		// List<Workbook> workbookList = new ArrayList<>();
		// workbookList.add(wb1);
		// workbookList.add(wb2);


		Map<String, List<Map<String, String>>> datas = new LinkedHashMap<>();
		datas.put("a", rowList2);
		rowList2.addAll(rowList3);
		datas.put("b", rowList2);
		rowList3.addAll(rowList2);
		datas.put("c", rowList3);

		// excelTool.exportExcel(titleData, datas, "D://outExcel2.xlsx", true, true);
		excelTool2.exportExcel(columnsMap, datas, "D://outExcel.xlsx", true, true);

		// Result result = excelTool.exportExcel(workbookList, "测试");

		//读取excel
//          ExcelTool excelTool = new ExcelTool();
//          List<List<String>> readexecl=excelTool.getExcelValues("D://outExcel.xls",1);
//          List<List<Map<String,String>>> readexeclC=excelTool.getExcelMapVal("D://outExcel.xls",1);
//          int count= excelTool.hasSheetCount("D://outExcel.xls");

	}
}
